// console.log("+-------------------------------+");
// console.log("| \t循环语句 \t\t|");
// console.log("+-------------------------------+");

/**
 * 重复性的执行某段代码
 */

function title(tit) {
    tit += "";
    // 字符串转化成数组 每个字符占一个元素
    var tits = tit.split("")
    var titLenght = 0;
    for (let i = 0; i < tits.length; i++) {
        const elem = tits[i];
        if (elem.charCodeAt(elem) > 255) {
            titLenght += 2;
        } else {
            titLenght += 1;
        }
    }
    var spaceNum = 24 - titLenght;
    var leftSpaceNum = parseInt(spaceNum/2)
    var rightSpaceNum = spaceNum-leftSpaceNum;
    
    var leftSpaceStr = "";
    var rightSpaceStr = "";
    for (let i = 0; i < leftSpaceNum; i++) {
        leftSpaceStr += " "
    }
    for (let i = 0; i < rightSpaceNum; i++) {
        rightSpaceStr+= " "
    }
    var logString = "|"+leftSpaceStr+tit +rightSpaceStr +"|"
    
    console.log("+------------------------+");
    console.log(logString);
    console.log("+------------------------+");
}


title("循环语句")